package com.fyzk.activity.prize.detail;

import android.os.Bundle;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.fyzk.base.BaseActivity;
import com.fyzk.activity.prize.InquiryInfo;
import com.fyzk.activity.prize.item.PrizeItemBase;
import com.fyzk.activity.prize.item.PrizeItemFactory;
import com.fyzk.bean.AwardDetail;
import com.fyzk.data.AppLotteryInfos;
import com.fyzk.dialog.DJ_ProgressDialog;
import com.fyzk.interfaces.onTopTitleClickListener;
import com.tyjc.lottery.R;
import com.fyzk.net.Commands;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.view.TopTitleView;

import org.json.JSONException;
import org.json.JSONObject;

import http.Common.CommandUtil;
import http.StringResultBean;

/**
 * 开奖详情页
 */
public class PrizeDetailActivity extends BaseActivity implements
        onTopTitleClickListener {
    private TopTitleView mVi_topTitle;
    private PrizeSelectDetailTopView mVi_prizeNumView;
    private PrizeDetailSalesBonusView mVi_salesAndBonus;
    private PrizeDetailAwardLevelView mVi_levelDetail;
    private int mStr_lotteryID;
    private String mStr_lotteryPeriod;
    private String mStr_prizeNum;//
    private String mStr_prizeDate;//
    private String mStr_peroid;//
    private String mStr_sumCode;//

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dj_activity_prizedetail);
        mStr_lotteryID = getIntent().getIntExtra(IntentParamUtils.LOTTERYID, 0);
        mStr_lotteryPeriod = getIntent()
                .getStringExtra(IntentParamUtils.PERIOD);
        mStr_prizeNum = getIntent().getStringExtra(IntentParamUtils.PRIZENUM);
        mStr_prizeDate = getIntent().getStringExtra(IntentParamUtils.DATE);
        init();
    }

    @Override
    protected void init() {
        mVi_topTitle = (TopTitleView) findViewById(R.id.topTitle);

        String lotteryName = AppLotteryInfos.getLotteryName(mStr_lotteryID);

        mVi_topTitle.setCenterText(lotteryName + getResources().getString(R.string.text_prizedetail_open));
        mVi_topTitle.setRightVisible(View.INVISIBLE);
        mVi_topTitle.setOnTitleClickListener(this);

        mVi_prizeNumView = (PrizeSelectDetailTopView) findViewById(R.id
				.ttc_activity_prizedetail_Vi_prizeball);
        mVi_prizeNumView.setLotteryName(lotteryName);
        mVi_prizeNumView.setDate(mStr_prizeDate);
        mVi_prizeNumView.setPeriod(mStr_lotteryPeriod);
        InquiryInfo info = new InquiryInfo(mStr_lotteryID, "", mStr_prizeNum, "",
				mStr_lotteryPeriod, mStr_prizeDate);
        PrizeItemBase prizeItem = PrizeItemFactory.getInstance().getPrizeItem(info);
        mVi_prizeNumView.setPrizeNum(prizeItem);

        mVi_salesAndBonus = (PrizeDetailSalesBonusView) findViewById(R.id
				.ttc_activity_prizedetail_Vi_salesBonus);
        mVi_levelDetail = (PrizeDetailAwardLevelView) findViewById(R.id
				.ttc_activity_prizedetail_Vi_levelView);
        DJ_ProgressDialog.show(getContext(), true, true);
        openPrizeDedtail();
    }

    private void openPrizeDedtail() {
        JSONObject params = new JSONObject();
        try {
            params.put("lotteryType", mStr_lotteryID);
            params.put("phase", mStr_lotteryPeriod);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        httpPostJson(CommandUtil.OPEN_LOTTERY_DETAIL, Commands.WINCODEDETAIL, params, true);
    }

    @Override
    protected void onSuccess(int requestCode, StringResultBean resultBean, String result) {
        super.onSuccess(requestCode, resultBean, result);
        if(resultBean.getErrorcode().equals("0")){
            AwardDetail detail = JSON.parseObject(resultBean.getData(),AwardDetail.class);
            mVi_salesAndBonus.setSales(detail.getSaleAmount());
            mVi_salesAndBonus.setBonus(detail.getPoolAmount());
            mVi_levelDetail.setAwardsList(detail.getLevels());
        }
    }

    @Override
    public void onLeftClick() {
        finish();
    }

    @Override
    public void onCenterClick() {
    }

    @Override
    public void onRightClick() {
    }

    @Override
    public void onRight2Click() {
    }
}